package day9;

import java.sql.*;
import java.util.Date;

/**
 * @author oldliu
 * @since 1.0
 */
public class Jdbc1 {
    public static void main(String[] args) {
        //jdbc
        try {
            Class.forName("com.mysql.cj.jdbc.Driver");
        } catch (ClassNotFoundException e) {
            e.printStackTrace();
            return;
        }
        String url="jdbc:mysql://localhost:3308/fuyang?autoReconnect=true&useUnicode=true&characterEncoding=utf8&serverTimezone=GMT%2B8";
        String user="root";
        String pass="root1234";
        try {
            Connection con = DriverManager.getConnection(url, user, pass);
            Statement st = con.createStatement();
            ResultSet rs = st.executeQuery("select * from user limit 0,20");
            while (rs.next()){
                //确定表中的类型和java中类型的对应
                long id = rs.getLong("id");
                String name = rs.getString("username");
                String telephone = rs.getString("telephone");
                Date enterdate = rs.getDate("enterdate");
                System.out.println(id+","+name+","+telephone+","+enterdate);
            }
            rs.close();
            st.close();
            con.close();//隐患
        } catch (SQLException e) {
            e.printStackTrace();
        }

    }
}
